// --------------------------------------------------------------------------
// XmlHandler.h
//
// Copyright 2007, Antony Pranata
// http://www.antonypranata.com
//
// Example how to parse XML file using SAX on Symbian OS.
//
// There are two methods to parse XML document, i.e.;
//   - StartParsingL() -> parse XML document without active object.
//     The whole file content is read at once. It is simple, but suitable
//     for relatively small file only.
//   - StartParsingWithAoL() -> parse XML document with active object.
//  
// 需要使用xmlframework.lib bafl.lib
// --------------------------------------------------------------------------

#ifndef __XMLHANDLER_H__
#define __XMLHANDLER_H__

// INCLUDE FILES
#include <e32base.h>
#include <xml\contenthandler.h> // for MContentHandler
#include <xml\parser.h> // for CParser


// CLASS DECLARATION
class CXmlNode;

using namespace Xml;

/**
 * MXmlHandlerObserver, an observer to CXmlHandler class.
 */
class MXmlHandlerObserver
{
	
public:
	virtual void OnXmlNodeParseCompletedL (TInt aError, CXmlNode *pXmlNode, TInt aSession) = 0;

};

/**
 * CXmlHandler, a class to parse XML file and then output log information
 * to a buffer.
 */
class CXmlHandler : public /* CActive, */MContentHandler
{
	enum TState
	{
		EIdle, EReadingFile
	};

public:
	// Constructors and destructor

	static CXmlHandler* NewL (MXmlHandlerObserver& aObserver );

	static CXmlHandler* NewLC (MXmlHandlerObserver& aObserver );

	virtual ~CXmlHandler ();

public:
	// Public methods

	void StartParsingL(RFs aFs, const TDesC& aFileName , TInt aSessionId);
	void StartParsingL(const TDesC8& aFragment, TInt aSessionId);
	//void StartParsingWithAoL( const TDesC& aFileName);
	
	/* TPtr DisplayResult()
	 { return iDisplayResult->Des(); }*/

private:
	// Constructors

	CXmlHandler (MXmlHandlerObserver& aObserver );

	void ConstructL ();


private:
	// from MContentHandler

	void OnStartDocumentL (const RDocumentParameters &aDocParam, TInt aErrorCode );

	void OnEndDocumentL (TInt aErrorCode );

	void OnStartElementL (const RTagInfo &aElement, const RAttributeArray &aAttributes, TInt aErrorCode );

	void OnEndElementL (const RTagInfo &aElement, TInt aErrorCode );

	void OnContentL (const TDesC8 &aBytes, TInt aErrorCode );

	void OnStartPrefixMappingL (const RString &aPrefix, const RString &aUri, TInt aErrorCode );

	void OnEndPrefixMappingL (const RString &aPrefix, TInt aErrorCode );

	void OnIgnorableWhiteSpaceL (const TDesC8 &aBytes, TInt aErrorCode );

	void OnSkippedEntityL (const RString &aName, TInt aErrorCode );

	void OnProcessingInstructionL (const TDesC8 &aTarget, const TDesC8 &aData, TInt aErrorCode );

	void OnError (TInt aErrorCode );

	TAny *GetExtendedInterface (const TInt32 aUid );


private:
	// Private data

	MXmlHandlerObserver& iObserver;
	CParser* iParser;
	
	CXmlNode 			*m_pXmlNode;
	
	TInt 				 m_sessionId;
	
};

#endif /* __XMLHANDLER_H__ */

// End of File
